<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../common/include/header.jsp" %>
<%@ page import="model.*" %>
<%-- 커뮤니티 신청 페이지 --%>
<div width="980px">
<table border="0" cellpadding="0" cellspacing="0" width="980px">
	<tr>
		<td style="vertical-align: top;width: 180px;background-color: #fdb32a;">
		
				<table border="0" cellpadding="0" cellspacing="0">
		<tr><td id="commTd" style="width: 180px;height: 40px;background: #000000;text-align: center;" onclick="javascript:location.href='<%=path %>/community/communitymain.do';" onmouseover="javascript:this.style.cursor='hand';">
			<span style="color: #ffffff;font-weight: bold;">커뮤니티 메인</span>
		</td>	</tr>
	
	<tr><td style="height: 20px;"><img src="<%=imagePath %>left_01.jpg"/></td></tr>
	<tr><td style="height: 20px;"><img src="<%=imagePath %>left_comm.jpg"/></td></tr>
			<logic:notEmpty name="communityForm" property="memberCommunitys">
				<form name="urlForm">
	<tr><td style="height: 20px;background-image: url('<%=imagePath %>left_02.jpg');text-align: center;padding-top:2px;">
					<select name="url" onchange="changeUrl()" style="width: 140px;height: 18px;font-size: 8pt;">
						<logic:iterate id="mc" name="communityForm" property="memberCommunitys" type="model.MemberCommunity">
							<option value="<bean:write name="mc" property="cono"/>"><bean:write name="mc" property="coname"/></option>
						</logic:iterate>
					</select>			
		</td></tr>
				</form>
			</logic:notEmpty>

	<tr><td style="height: 20px;"><img src="<%=imagePath %>left_03.jpg"/></td></tr>
				</table>
				
		</td>
		<td style="width: 800px;text-align: center;vertical-align: top;">		
			<!-- 실제 컨텐츠 화면 표시부분 -->
			
		<div>
			<!-- 입력정보부분 -->
			<table style="width: 800px;" cellpadding="0" cellspacing="0"> <!-- 외부 800테이블 -->
			<tr><td style="vertical-align: top;width: 600px;padding-top: 10px;">
			<html:form action="/communityinfo" enctype="multipart/form-data">
			<input type="hidden" name="method" value="receiveData"/>
			<table style="width: 500px;text-align:left;border: 1px solid black;" cellpadding="0" cellspacing="0"><!-- 내부 500테이블 (기본정보)-->
			  <tr>
				<td colspan="2" style="height: 40px;background: #000000;"><img src="<%=imagePath %>commadmin_info_02.jpg" border="0"/></td>
			  </tr>
			  <tr>
				<td style="width: 100px;height: 20px;"><img src="<%=imagePath %>comm_create_26.jpg" border="0"/></td>
			  	<td><bean:write name="user" property="mid" scope="session"/><input type="hidden" name="mid" value="<bean:write name="user" property="mid" scope="session"/>"></td>
			  </tr>
			  <tr>
				<td style="width: 100px;height: 20px;"><img src="<%=imagePath %>commadmin_info_05.jpg" border="0"/></td>
				<td style="width: 400px;height: 20px;"><input type="text" name="coname" class="commCreateForm" style="width: 300px;"></td>
			  </tr>
			  <tr>
				<td style="width: 100px;height: 60px;"><img src="<%=imagePath %>commadmin_info_07.jpg" border="0"/></td>
				<td><html:textarea property="coguide" style="height: 60px;width: 390px;"/></td>
			  </tr>
			  <tr>
				<td style="width: 100px;height: 20px;"><img src="<%=imagePath %>commadmin_info_08.jpg" border="0"/></td>
				<td>					
					<html:select property="ccno" style="height: 20px;font-size: 8pt;">
						<html:optionsCollection property="categorys" value="ccno" label="ccname"/>
					</html:select>
				</td>
			  </tr>
			  <tr>
				<td style="width: 100px;height: 20px;"><img src="<%=imagePath %>commadmin_info_09.jpg" border="0"/></td>
				<td>
					<html:select property="coopen" style="height: 20px;font-size: 8pt;">
						<html:option value="0">공개</html:option>
						<html:option value="1">비공개</html:option>
					</html:select>
				</td>
			  </tr>
			  <tr>
				<td style="width: 100px;height: 80px;"><img src="<%=imagePath %>commadmin_info_10.jpg" border="0"/></td>

				<td style="vertical-align: top;"><html:file property="file" onchange="changeFile(this.value)"  style="height: 20px;width: 390px;font-size: 8pt;"/><br/>
					<html:hidden property="cologosfn"/>
						<img id="photo" src="" style="display: none;width: 390px;height: 40px;"/>
				</td>							
			  </tr>
			  
  			  <tr>
				<td colspan="2" style="height: 20px;"><img src="<%=imagePath %>commadmin_info_11.jpg" border="0"/></td>
			  </tr>
  
			  <tr>
				<td style="width: 100px;height: 60px;"><img src="<%=imagePath %>commadmin_info_12.jpg" border="0"/></td>
				<td><html:textarea property="copoptext" style="height: 60px;width: 390px;"/></td>
			  </tr>

			  <tr>
				<td style="width: 100px;height: 20px;"><img src="<%=imagePath %>commadmin_info_14.jpg" border="0"/></td>
				<td style="height: 20px;">높이 : <html:text property="copopheight" styleClass="commPopupSize"/>&nbsp;&nbsp;&nbsp;&nbsp;
				넓이 : <html:text property="copopwidth" styleClass="commPopupSize"/></td>
			  </tr>

			</table><!-- 커뮤니티 기본정보 테이블 끝 -->
			  <div style="height: 10px;"></div>
						<%int count=1; %>
						<table id="tableObj" style="width: 500px; border: 1px solid #999999;" cellpadding="0" cellspacing="0"> 
							<tr>
								<td colspan="2" style="height: 40px;background: #000000;"><img src="<%=imagePath %>commadmin_info_15.jpg" border="0"/></td>
							</tr>
							<tr>
								<td style="width: 200px;height: 20px;"><img src="<%=imagePath %>commadmin_info_16.jpg" border="0"/></td>
								<td style="width: 300px;height: 20px;text-align: left;"><img src="<%=imagePath %>commadmin_info_17.jpg" border="0"/></td>
							</tr>
								<tr>
									<td style="width: 200px;height: 20px;"><input type="text" name="linkname<%=count%>" class="commLinkSize" style="width: 190px;"/></td>
									<td style="width: 250px;height: 20px;"><input type="text" name="linkaddress<%=count%>" class="commLinkSize" style="width: 240px;"/></td>
								</tr>
								<input type="hidden" name="linkcount" id="lc" value=<%=count%>>
								<input type="hidden" name="isLink" value="false">

							<input type="hidden" name="linkcount2" id="lc" value=<%=count%>>	
							
						</table>
			<!-- 내부 500 테이블 끝 -->
					<div style="width: 500px;height: 40px;text-align: center;padding-top: 10px;">							
							<img src="<%=imagePath %>commadmin_info_20.jpg" border="0" onClick="javascript:addItem()" onmouseover="this.style.cursor = 'hand'"/>
							<img src="<%=imagePath %>commadmin_info_21.jpg" border="0" onClick="javascript:removeItem()" onmouseover="this.style.cursor = 'hand'"/>
					</div>

					<div style="width: 500px;height: 40px;text-align: right;">
						<img id="sbbutton" src="<%=imagePath %>comm_create_28.jpg" border="0" onclick="javascript:formcheck();" onmouseover="this.style.cursor = 'hand'"/>
						<img src="<%=imagePath %>commadmin_info_24.jpg" border="0" onclick="javascript:history.go(-1)" onmouseover="this.style.cursor = 'hand'"/>
					</div>

			</html:form>								
				</td>
				<td><img src="<%=imagePath %>commadmin_info_04.jpg" border="0"/>
				</td>
				</tr>
			</table><!-- 외부 800 테이블 끝 -->

		</div>
		</td>
	</tr>
</table>
<script type="text/javascript">

	//파일의 확장자 가져오기
	function getFileExtension(filePath){
	    var lastIndex = -1;
	    lastIndex = filePath.lastIndexOf('.');
	    var extension = "";
	
		if(lastIndex != -1){
		    extension = filePath.substring(lastIndex + 1, filePath.len);
		}else{
		    extension = "";
		}
		return extension;
	}

	//파일 선택했을 때 검사
	function changeFile(filesrc){

		var check = getFileExtension(filesrc);
	   
	    if(!((check.toLowerCase()=="jpg") || (check.toLowerCase()=="jpeg") || (check.toLowerCase()=="gif"))){
	        document.getElementById("sbbutton").disabled = true;
	        alert("jpg, jpeg, gif 파일만 올려주세요~!");
	        return;
	    }
	    
	    document.getElementById("sbbutton").disabled = false;
	    
	    var img = new Image();
		img.src = filesrc;
		if(img.fileSize > 500*1024){
	    	alert('500kb가 넘어 갑니다.');
	    	return false;
	    }
		document.getElementById('photo').style.display="";
		document.getElementById('photo').src=filesrc;		
	}
	
	//커뮤니티 바로가기 선택했을 때
	function changeUrl(){
		var selectedIndex = window.document.urlForm.url.selectedIndex;
		if(selectedIndex==0){}
		else{
			var url=window.document.urlForm.url.options[selectedIndex].value;
			if(url!=0){
				url = '<%=path%>/community/community.do?cono='+url;
				window.open(url,"_self");
			}
		}
	}
	
	//링크 추가하기
	function addItem(){ 
            var rows  = tableObj.rows.length;
            var linkcount = document.getElementById('lc');
		  	linkcount.value = parseInt(linkcount.value)+1;
		  	
            newTr=tableObj.insertRow(rows);
            _td = document.createElement('<TD>')
	        _td.style.width = "250";
            _td.style.textAlign = "left";
  	 		newTd=newTr.insertCell(_td);
  	 		var addressadd = '<input type="text" name="linkaddress'+linkcount.value+'" class="commLinkSize" style="width: 240px;"/>';
	  	 	newTd.insertAdjacentHTML('afterBegin',addressadd);
	  	 	
            _td = document.createElement('<TD>')
            _td.style.width = "200";
  	 		newTd=newTr.insertCell(_td);
		 	var nameadd = '<input type="text" name="linkname'+linkcount.value+'" class="commLinkSize" style="width: 190px;"/>';
		  	newTd.insertAdjacentHTML('afterBegin',nameadd);
    }
    
    //링크삭제하기
    function removeItem(){
		var rows  = parseInt(tableObj.rows.length);
		if(rows>2){
			tableObj.deleteRow(rows-1);
			var linkcount = document.getElementById('lc');
			linkcount.value = parseInt(linkcount.value)-1;
		}else{
			alert('더이상 삭제 안됩니다');
		}
	}
	
	function check(){
		<%	boolean check = user.isLogon();
			if(check){	%>
				return true;
		<%	}else{	%>
				alert("로그인 후 이용가능 합니다.");
				return false;
		<%	}	%>
	}
	
	//전송하기 전에 다시한번 체크
	function formcheck(){
		var coname = document.getElementById('coname').value;
		var coguide = document.getElementById('coguide').value;
		var reconame = coname.replace(/\s/g,'');
		var recoguide = coguide.replace(/\s/g,'');
		if(reconame.length <1){
			alert('커뮤니티명은 필수 입력 사항입니다.');
			return false;
		}
		
		if(recoguide.length<30){
			alert('커뮤니티 설명은 공백 제외 30자 이상입니다.');
			return false;
		}
		
		var linkcount = parseInt(document.getElementById('lc').value);
		for(var i=1;i<linkcount+1;i++){
			var link1 = "linkname"+i;
			var link2 = "linkaddress"+i;
			var linkname = document.getElementById(link1).value;
			var linkaddress = document.getElementById(link2).value;
			var relinkname = linkname.replace(/\s/g,'');
			var relinkaddress = linkaddress.replace(/\s/g,'');
			
			if(relinkname.length>0){
				if(relinkaddress.length<1){
					alert('링크주소를 입력해주세요');
					return false;
				}
			}
			
			if(relinkaddress.length>0){
				if(relinkname.length<1){
					alert('링크명을 입력해주세요');
					return false;
				}
				var sublink = relinkaddress.substr(0,7);
				if(sublink != "http://"){
					document.getElementById(link2).value='http://'+linkaddress;
				}
			}			
		}
		
		communityForm.submit();
		
	}

</script>
</div>
<%@ include file="../common/include/footer.jsp" %>